import 'package:get/get.dart';

import '../../../../../config/RouteConfig.dart';
import '../../../config/GlobalConfig.dart';
import '../../../util/HDNavigator.dart';
import '../../../util/location/location_gaode.dart';
import 'state.dart';

class ApplicationLogic extends GetxController {
  final ApplicationState state = ApplicationState();

  @override
  void onInit() {
    super.onInit();
    initPermissionData();
  }

  /// 初始化数据集合
  initPermissionData() {
    if (GlobalConfig.loginEntity?.menuPermissionCode != null) {
      if((GlobalConfig.loginEntity?.menuPermissionCode ?? []).isEmpty){
        state.takan = true;
        state.construction = true;
        state.business = true;
        state.gridNet = true;
        state.startApproval = true;
        state.operationToll = true;
      }
      for (var element in (GlobalConfig.loginEntity?.menuPermissionCode ?? [])) {
        switch (element) {
          case "0":
            state.business = true;
            state.businessList.add(PermitItem(
                "customerProfile", "assets/images/customer_profile.png", "客户档案"));
            break;
          case "1":
            state.business = true;
            state.businessList.add(
                PermitItem("addCustomer", "assets/images/add_customer.png", "客户录入"));
            break;
          case "2":
            state.takan = true;
            break;
          case "3":
            break;
          case "4":
            state.startApproval = true;
            break;
          case "5":
            state.construction = true;
            break;
          case "6":
            state.gridNet = true;
            break;
          case "7":
            break;
          case "8":
            break;
          case "9":
            state.operationToll = true;
            break;
        }
      }
    }
    // TODO 应用的二级权限

    state.explorationList.add(
        PermitItem("unExploration", "assets/images/unexploration.png", "待踏勘"));
    state.explorationList.add(PermitItem(
        "explorationRecord", "assets/images/exploration_record.png", "踏勘记录"));

    state.startApprovalList
        .add(PermitItem("unApproval", "assets/images/un_approval.png", "待报审"));
    state.startApprovalList.add(
        PermitItem("approvalRecord", "assets/images/approval_rd.png", "报审记录"));

    state.constructionList.add(PermitItem(
        "unInspectionTask", "assets/images/inspect_icon.png", "待施工"));
    state.constructionList.add(
        PermitItem("inspectionRecord", "assets/images/con_record.png", "施工记录"));

    state.bingWangList
        .add(PermitItem("unNet", "assets/images/un_task.png", "待并网"));
    state.bingWangList.add(
        PermitItem("netRecord", "assets/images/bingwang.png", "并网记录"));
    state.operationTollList.add(PermitItem(
        "operationTask", "assets/images/un_inspection_task.png", "待运维"));
    state.operationTollList.add(PermitItem(
        "operationRecord", "assets/images/operation_record.png", "运维记录"));
  }

  /// item点击 type：1:商务，勘探，巡检
  clickPermitItem(int type, PermitItem item) {
    if (type == 1) {
      switch (item.code) {
        case "addCustomer":
          HDNavigator.openToName(RouteConfig.addBusiness);
          break;
        case "customerProfile":
          HDNavigator.openToName(RouteConfig.customerProfile);
          break;
      }
    } else if (type == 2) {
      switch (item.code) {
        case "unExploration":
          HDNavigator.openToName(RouteConfig.explorationTask);
          break;
        case "explorationRecord":
          HDNavigator.openToName(RouteConfig.explorationRecord);
          break;
      }
    } else if (type == 3) {
      switch (item.code) {
        case "unApproval":
          HDNavigator.openToName(RouteConfig.unApproval);
          break;
        case "approvalRecord":
          HDNavigator.openToName(RouteConfig.approvalRecord);
          break;
      }
    } else if (type == 4) {
      switch (item.code) {
        case "unInspectionTask":
          HDNavigator.openToName(RouteConfig.unConstruct);
          break;
        case "inspectionRecord":
          HDNavigator.openToName(RouteConfig.constructRecord);
          break;
      }
    } else if (type == 5) {
      switch (item.code) {
        case "unNet":
          HDNavigator.openToName(RouteConfig.unNet);
          break;
        case "netRecord":
          HDNavigator.openToName(RouteConfig.netRecord);
          break;
      }
    }else if (type == 6) {
      switch (item.code) {
        case "addOperation":
          HDNavigator.openToName(RouteConfig.addOperation);
          break;
        case "operationTask":
          HDNavigator.openToName(RouteConfig.operationTask);
          break;
        case "operationRecord":
          HDNavigator.openToName(RouteConfig.operationRecord);
          break;
      }
    }
  }
}
